﻿/* 变量 */
var footmarklist = "footmark/footMarkTab.html";
var footmarkdetail = "footmark/footMarkDetail.html"
var newfootmark = "footmark/newFootMark.html";

//列表
var contactsCallback_footmarklist = myApp.onPageInit('footmarklist', function (page) {

    //点击第一次页面执行
    var flag_tab = true;
    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;

    var index_tab1 = 1;
    var index_tab2 = 1;
    var index_tab3 = 1;
    var current_tabindex = 0;
    var size = 10;

    //获取页面参数
    var userID = ISS.utils.getParameter("userID");
    if (userID && userID != undefined && userID != null && userID != "") {
        iss_localStorage.set("yuqing_appUserId", userID);
    }
    LoadStayAll(index_tab1, size);

    //加载数据
    function LoadStayAll(pageindex, pagesize) {
        if (current_tabindex == 0 && index_tab1 == 1) {
            $$("#sub_tab1 ul").html("");
        } else if (current_tabindex == 1 && index_tab2 == 1) {
            $$("#sub_tab2 ul").html("");
        } else if (current_tabindex == 2 && index_tab3 == 1) {
            $$("#sub_tab3 ul").html("");
        }
        if (current_tabindex == 0) {
            // JSON
            var _conditionParams = JSON.stringify({
                type: 0,
                UserID: iss_localStorage.get("yuqing_appUserId"),
                BookType: 1,
                pageIndex: 1,
                pageSize: 10
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                crossDomain: true,
                data: { "content": _conditionParams },
                method: "POST",
                success: function (data, status) {
                    myApp.hidePreloader();
                    data = JSON.parse(data);
                    console.log(data);
                    // 删除加载提示符
                    $$('.infinite-scroll-preloader1').remove();
                    // 加载完毕，则注销无限加载事件，以防不必要的加载
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (data && data.status == "0" && data.results.length > 0) {
                        var p2html = "";
                        var searchTemplate = $$('#template-footmarklist-info').html();
                        if (searchTemplate) {
                            var compiledTemplate = Template7.compile(searchTemplate);
                            p2html += compiledTemplate(data);
                            $$("#footmarklist #sub_tab1 .page-content ul").html(p2html);
                            //默认隐藏多篇日记
                            $$('#footmarklist #sub_tab1 .footmark-card').each(function () {
                                $$(this).find('.footmark-list').each(function (i, v) {
                                    if (i != 0) {
                                        $$(this).css('display', 'none')
                                    }
                                })
                            })
                            //展开或者收起日记
                            $$('#footmarklist #sub_tab1 .footmark-tool').on('click', function () {
                                var tool = $$(this);
                                $$(this).parent().parent().find('.footmark-list').each(function (i, k) {
                                    if (i != 0 && tool.text() == "收起") {
                                        $$(this).removeAttr('style')
                                        $$(this).css('display', 'none')
                                    } else if (i != 0 && tool.text() == "展开") {
                                        $$(this).removeAttr('style')
                                        $$(this).css('display', 'block')
                                    }
                                })
                                if (tool.text() == "收起") {
                                    tool.find('.close').html('展开 <i class="iconfont icon-jiantou-down"></i>')
                                } else {
                                    tool.find('.close').html('收起 <i class="iconfont icon-jiantou-up"></i>')
                                }
                            })
                            //点赞
                            $$('#footmarklist #sub_tab1 .active').on('click', function () {

                                var _conditionParams = "";
                                var _type = $$(this).attr("islike") == "1" ? 102 : 101;
                                _conditionParams = JSON.stringify({
                                    type: _type,
                                    like: {
                                        Code: $$(this).attr('code'),
                                        UserID: iss_localStorage.get("yuqing_appUserId"),

                                    }
                                });
                                var dz = $(this);
                                $$.ajax({
                                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKLIKE,
                                    crossDomain: true,
                                    data: { "content": _conditionParams },
                                    method: "POST",
                                    success: function (data, status) {
                                        var jdata = JSON.parse(data).results;
                                        if (_type == 102) {
                                            dz.attr("islike", "0");
                                            dz.find('i').removeClass("icon-zan");
                                            dz.find('i').addClass("icon-zank");
                                            var likecount = parseInt(dz.find(".likecount").html()) - 1;
                                            dz.find(".likecount").html(likecount);
                                        } else {
                                            dz.attr("islike", "1");
                                            dz.find('i').removeClass("icon-zank");
                                            dz.find('i').addClass("icon-zan");
                                            var likecount = parseInt(dz.find(".likecount").html()) + 1;
                                            dz.find(".likecount").html(likecount);
                                        }
                                    },
                                    error: function (xhr, status) {
                                        myApp.alert('点赞失败')
                                    }
                                });
                            })
                            //收藏
                            $$('#footmarklist #sub_tab1 .collection').on('click', function () {
                                var _conditionParams = "";
                                var _type = $$(this).attr("iscollection") == "1" ? 103 : 4;
                                _conditionParams = JSON.stringify({
                                    type: _type,
                                    collection: {
                                        Code: $$(this).attr('code'),
                                        UserID: iss_localStorage.get("yuqing_appUserId")
                                    }
                                });
                                var sc = $$(this);
                                $$.ajax({
                                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKCOLLECTION,
                                    crossDomain: true,
                                    data: { "content": _conditionParams },
                                    method: "POST",
                                    success: function (data, status) {
                                        var jdata = JSON.parse(data).results;
                                        if (_type == 103) {
                                            sc.attr("iscollection", "0");
                                            sc.find('i').removeClass("icon-shoucang");
                                            sc.find('i').addClass("icon-shoucangk");
                                            var collectioncount = parseInt(sc.find(".collectioncount").html()) - 1;
                                            sc.find(".collectioncount").html(collectioncount);
                                        } else {
                                            sc.attr("iscollection", "1");
                                            sc.find('i').removeClass("icon-shoucangk");
                                            sc.find('i').addClass("icon-shoucang");
                                            var collectioncount = parseInt(sc.find(".collectioncount").html()) + 1;
                                            sc.find(".collectioncount").html(collectioncount);
                                        }
                                    },
                                    error: function (xhr, status) {
                                        myApp.alert('收藏失败')
                                    }
                                });
                            })
                            //图片浏览
                            $$('#footmarklist #sub_tab1 .pic-box').on('click', function (e) {
                                photoview($$(this).find('div'));
                                e.preventDefault();
                            })
                            //弹出回复
                            $$('#footmarklist #sub_tab1 .comment-enter').on('click', function (e) {
                                $(this).parent().after('<div class="inputcomment" code="' + $$(this).parent().attr('code') + '" style="width:100%;position: absolute;"><div class="item-input" style="background-color: #f9f9f9;padding: 6px;border-top: 0.2px solid #d8d8d8;"><input class="pl" type="text" name="comment"placeholder="评论"style="width: 80%;height: 25px;border: 1px solid #f2f2f2;padding: 0 8px;"><a class="sendm" href="#" style="width: 15%;font-size: 12px;margin-left: 10px;">发送</a></div></div>')

                                //键盘弹起不遮挡输入框
                                var target = $$('.pl');
                                setTimeout(function () {
                                    target.scrollIntoViewIfNeeded();
                                }, 100);

                                if (/Android [4-6]/.test(navigator.appVersion)) {
                                    window.addEventListener("resize", function () {
                                        if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
                                            window.setTimeout(function () {
                                                document.activeElement.scrollIntoViewIfNeeded();
                                            }, 0);
                                        }
                                    })
                                }
                                //得到焦点
                                $$('.pl').focus();

                                //失去焦点弹出层隐藏，绑定发送消息
                                $$(".pl").blur(function (e) {
                                    //发送回复
                                    $$('#sub_tab1 .sendm').on('click', function (e) {
                                        if ($$(".pl").val() == "") return false;
                                        var _conditionParams = "";
                                        var _type = 107;
                                        _conditionParams = JSON.stringify({
                                            type: _type,
                                            comment: {
                                                Code: $$(this).parent().parent().attr('code'),
                                                UserID: iss_localStorage.get("yuqing_appUserId"),
                                                Content: $$(".pl").val()
                                            }
                                        });
                                        var dz = $$(this);
                                        $$.ajax({
                                            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTCOMMENT,
                                            crossDomain: true,
                                            data: { "content": _conditionParams },
                                            method: "POST",
                                            success: function (data, status) {
                                                myApp.alert('点评成功，请等待审核');
                                            },
                                            error: function (xhr, status) {
                                                myApp.alert('点评失败');
                                            }
                                        });
                                    })
                                    setTimeout(function () {
                                        $$(".inputcomment").remove();
                                    }, 200
                                    )

                                });
                            })
                        }
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert("服务器连接失败！")
                }
            });
        }
        else if (current_tabindex == 1) {
            var _conditionParams = JSON.stringify({
                type: 0,
                UserID: iss_localStorage.get("yuqing_appUserId"),
                BookType: 0,
                pageIndex: 1,
                pageSize: 10
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                crossDomain: true,
                data: { "content": _conditionParams },
                method: "POST",
                success: function (data, status) {
                    myApp.hidePreloader();
                    data = JSON.parse(data);
                    console.log(data);
                    // 删除加载提示符
                    $$('.infinite-scroll-preloader2').remove();
                    // 加载完毕，则注销无限加载事件，以防不必要的加载
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (data && data.status == "0" && data.results.length > 0) {
                        var p2html = "";
                        var searchTemplate = $$('#template-footmarklist-newinfo').html();
                        if (searchTemplate) {
                            var compiledTemplate = Template7.compile(searchTemplate);
                            p2html += compiledTemplate(data);
                            $$("#footmarklist #sub_tab2 .page-content ul").html(p2html);
                            //默认隐藏多篇日记
                            $$('#footmarklist #sub_tab2 .footmark-card').each(function () {
                                $$(this).find('.footmark-list').each(function (i, v) {
                                    if (i != 0) {
                                        $$(this).css('display', 'none')
                                    }
                                })
                            })
                            //展开或者收起日记
                            $$('#footmarklist #sub_tab2 .footmark-tool').on('click', function () {
                                var tool = $$(this);
                                $$(this).parent().parent().find('.footmark-list').each(function (i, k) {
                                    if (i != 0 && tool.text() == "收起") {
                                        $$(this).removeAttr('style')
                                        $$(this).css('display', 'none')
                                    } else if (i != 0 && tool.text() == "展开") {
                                        $$(this).removeAttr('style')
                                        $$(this).css('display', 'block')
                                    }
                                })
                                if (tool.text() == "收起") {
                                    tool.find('.close').html('展开 <i class="iconfont icon-jiantou-down"></i>')
                                } else {
                                    tool.find('.close').html('收起 <i class="iconfont icon-jiantou-up"></i>')
                                }
                            })
                            //点赞
                            $$('#footmarklist #sub_tab2 .active').on('click', function () {
                                var _conditionParams = "";
                                var _type = $$(this).attr("islike") == "1" ? 102 : 101;
                                _conditionParams = JSON.stringify({
                                    type: _type,
                                    like: {
                                        Code: $$(this).attr('code'),
                                        UserID: iss_localStorage.get("yuqing_appUserId"),

                                    }
                                });
                                var dz = $$(this);
                                $$.ajax({
                                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKLIKE,
                                    crossDomain: true,
                                    data: { "content": _conditionParams },
                                    method: "POST",
                                    success: function (data, status) {
                                        var jdata = JSON.parse(data).results;
                                        if (_type == 102) {
                                            dz.attr("islike", "0");
                                            dz.find('i').removeClass("icon-zan");
                                            dz.find('i').addClass("icon-zank");
                                            var likecount = parseInt(dz.find(".likecount").html()) - 1;
                                            dz.find(".likecount").html(likecount);
                                        } else {
                                            dz.attr("islike", "1");
                                            dz.find('i').removeClass("icon-zank");
                                            dz.find('i').addClass("icon-zan");
                                            var likecount = parseInt(dz.find(".likecount").html()) + 1;
                                            dz.find(".likecount").html(likecount);
                                        }
                                    },
                                    error: function (xhr, status) {
                                        myApp.alert("点赞失败！")
                                    }
                                });
                            })
                            //收藏
                            $$('#footmarklist #sub_tab2 .collection').on('click', function () {
                                var _conditionParams = "";
                                var _type = $$(this).attr("iscollection") == "1" ? 103 : 4;
                                _conditionParams = JSON.stringify({
                                    type: _type,
                                    collection: {
                                        Code: $$(this).attr('code'),
                                        UserID: iss_localStorage.get("yuqing_appUserId")
                                    }
                                });
                                var sc = $$(this);
                                $$.ajax({
                                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKCOLLECTION,
                                    crossDomain: true,
                                    data: { "content": _conditionParams },
                                    method: "POST",
                                    success: function (data, status) {
                                        var jdata = JSON.parse(data).results;
                                        if (_type == 103) {
                                            sc.attr("iscollection", "0");
                                            sc.find('i').removeClass("icon-shoucang");
                                            sc.find('i').addClass("icon-shoucangk");
                                            var collectioncount = parseInt(sc.find(".collectioncount").html()) - 1;
                                            sc.find(".collectioncount").html(collectioncount);
                                        } else {
                                            sc.attr("iscollection", "1");
                                            sc.find('i').removeClass("icon-shoucangk");
                                            sc.find('i').addClass("icon-shoucang");
                                            var collectioncount = parseInt(sc.find(".collectioncount").html()) + 1;
                                            sc.find(".collectioncount").html(collectioncount);
                                        }
                                    },
                                    error: function (xhr, status) {
                                        myApp.alert("收藏失败！");
                                    }
                                });
                            })
                            //图片浏览
                            $$('#footmarklist #sub_tab2 .pic-box').on('click', function (e) {
                                photoview($$(this).find('div'));
                                e.preventDefault();
                            })
                            //弹出回复
                            $$('#footmarklist #sub_tab2 .comment-enter').on('click', function (e) {
                                $(this).parent().after('<div class="inputcomment" code="' + $$(this).parent().attr('code') + '" style="width:100%;position: absolute;"><div class="item-input" style="background-color: #f9f9f9;padding: 6px;border-top: 0.2px solid #d8d8d8;"><input class="pl" type="text" name="comment"placeholder="评论"style="width: 80%;height: 25px;border: 1px solid #f2f2f2;padding: 0 8px;"><a class="sendm" href="#" style="width: 15%;font-size: 12px;margin-left: 10px;">发送</a></div></div>')
                                //键盘弹起不遮挡输入框
                                var target = $$('.pl');
                                setTimeout(function () {
                                    target.scrollIntoViewIfNeeded();
                                }, 100);

                                if (/Android [4-6]/.test(navigator.appVersion)) {
                                    window.addEventListener("resize", function () {
                                        if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
                                            window.setTimeout(function () {
                                                document.activeElement.scrollIntoViewIfNeeded();
                                            }, 0);
                                        }
                                    })
                                }
                                //得到焦点
                                $$('.pl').focus();
                                //失去焦点弹出层隐藏，绑定发送消息
                                $$(".pl").blur(function (e) {
                                    //发送回复
                                    $$('#sub_tab2 .sendm').on('click', function (e) {
                                        if ($$(".pl").val() == "") return false;
                                        var _conditionParams = "";
                                        var _type = 107;
                                        _conditionParams = JSON.stringify({
                                            type: _type,
                                            comment: {
                                                Code: $$(this).parent().parent().attr('code'),
                                                UserID: iss_localStorage.get("yuqing_appUserId"),
                                                Content: $$(".pl").val()
                                            }
                                        });
                                        var dz = $$(this);
                                        $$.ajax({
                                            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTCOMMENT,
                                            crossDomain: true,
                                            data: { "content": _conditionParams },
                                            method: "POST",
                                            success: function (data, status) {
                                                myApp.alert('点评成功，请等待审核');
                                            },
                                            error: function (xhr, status) {
                                                myApp.alert('点评失败');
                                            }
                                        });
                                    })
                                    setTimeout(function () {
                                        $$(".inputcomment").remove();
                                    }, 200
                                    )

                                });
                            })
                        }
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert("服务器连接失败！")
                }
            });

        }
        else if (current_tabindex == 2) {
            var _conditionParams = JSON.stringify({
                type: 0,
                UserID: iss_localStorage.get("yuqing_appUserId"),
                BookType: 3,
                pageIndex: 1,
                pageSize: 10
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                crossDomain: true,
                data: { "content": _conditionParams },
                method: "POST",
                success: function (data, status) {
                    myApp.hidePreloader();
                    data = JSON.parse(data);
                    // 删除加载提示符
                    $$('.infinite-scroll-preloader3').remove();
                    // 加载完毕，则注销无限加载事件，以防不必要的加载
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    console.log(data);
                    if (data && data.status == "0" && data.results.length > 0) {
                        var p2html = "";
                        var searchTemplate = $$('#template-footmarklist-myinfo').html();
                        if (searchTemplate) {
                            var compiledTemplate = Template7.compile(searchTemplate);
                            p2html += compiledTemplate(data);
                            $$("#footmarklist #sub_tab3 .page-content ul").html(p2html);
                            //默认隐藏多篇日记
                            $$('#footmarklist #sub_tab3 .footmark-card').each(function () {
                                $$(this).find('.footmark-list').each(function (i, v) {
                                    if (i != 0) {
                                        $$(this).css('display', 'none')
                                    }
                                })
                            })
                            //展开或者收起日记
                            $$('#footmarklist #sub_tab3 .footmark-tool').on('click', function () {
                                var tool = $$(this);
                                $$(this).parent().parent().find('.footmark-list').each(function (i, k) {
                                    if (i != 0 && tool.text() == "收起") {
                                        $$(this).removeAttr('style')
                                        $$(this).css('display', 'none')
                                    } else if (i != 0 && tool.text() == "展开") {
                                        $$(this).removeAttr('style')
                                        $$(this).css('display', 'block')
                                    }
                                })
                                if (tool.text() == "收起") {
                                    tool.find('.close').html('展开 <i class="iconfont icon-jiantou-down"></i>')
                                } else {
                                    tool.find('.close').html('收起 <i class="iconfont icon-jiantou-up"></i>')
                                }
                            })
                            //点赞
                            $$('#footmarklist #sub_tab3 .active').on('click', function () {
                                var _conditionParams = "";
                                var _type = $$(this).attr("islike") == "1" ? 102 : 101;
                                _conditionParams = JSON.stringify({
                                    type: _type,
                                    like: {
                                        Code: $$(this).attr('code'),
                                        UserID: iss_localStorage.get("yuqing_appUserId"),

                                    }
                                });
                                var dz = $$(this);
                                $$.ajax({
                                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKLIKE,
                                    crossDomain: true,
                                    data: { "content": _conditionParams },
                                    method: "POST",
                                    success: function (data, status) {
                                        var jdata = JSON.parse(data).results;
                                        if (_type == 102) {
                                            dz.attr("islike", "0");
                                            dz.find('i').removeClass("icon-zan");
                                            dz.find('i').addClass("icon-zank");
                                            var likecount = parseInt(dz.find(".likecount").html()) - 1;
                                            dz.find(".likecount").html(likecount);
                                        } else {
                                            dz.attr("islike", "1");
                                            dz.find('i').removeClass("icon-zank");
                                            dz.find('i').addClass("icon-zan");
                                            var likecount = parseInt(dz.find(".likecount").html()) + 1;
                                            dz.find(".likecount").html(likecount);
                                        }
                                    },
                                    error: function (xhr, status) {
                                        myApp.alert("点赞失败！");
                                    }
                                });
                            })
                            //图片浏览
                            $$('#footmarklist #sub_tab3 .pic-box').on('click', function (e) {
                                photoview($$(this).find('div'));
                                e.preventDefault();
                            })
                            //删除
                            $$('#footmarklist #sub_tab3 .delete').on('click', function () {
                                var _conditionParams = "";
                                var _type = 105;
                                _conditionParams = JSON.stringify({
                                    type: _type,
                                    Code: $$(this).attr('code'),
                                    UserID: iss_localStorage.get("yuqing_appUserId")
                                });
                                var dz = $$(this);
                                $$.ajax({
                                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                                    crossDomain: true,
                                    data: { "content": _conditionParams },
                                    method: "POST",
                                    success: function (data, status) {
                                        var status = JSON.parse(data).status;
                                        if (status == 0) {
                                            dz.parent().parent().parent().remove();
                                            myApp.alert('删除成功');
                                        } else {
                                            myApp.alert('删除异常');
                                        }
                                    },
                                    error: function (xhr, status) { }
                                });
                            })
                            //弹出回复
                            $$('#footmarklist #sub_tab3 .comment-enter').on('click', function (e) {
                                $(this).parent().after('<div class="inputcomment" code="' + $$(this).parent().attr('code') + '" style="width:100%;position: absolute;"><div class="item-input" style="background-color: #f9f9f9;padding: 6px;border-top: 0.2px solid #d8d8d8;"><input class="pl" type="text" name="comment"placeholder="评论"style="width: 80%;height: 25px;border: 1px solid #f2f2f2;padding: 0 8px;"><a class="sendm" href="#" style="width: 15%;font-size: 12px;margin-left: 10px;">发送</a></div></div>')
                                //键盘弹起不遮挡输入框
                                var target = $$('.pl');
                                setTimeout(function () {
                                    target.scrollIntoViewIfNeeded();
                                }, 100);

                                if (/Android [4-6]/.test(navigator.appVersion)) {
                                    window.addEventListener("resize", function () {
                                        if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
                                            window.setTimeout(function () {
                                                document.activeElement.scrollIntoViewIfNeeded();
                                            }, 0);
                                        }
                                    })
                                }
                                //得到焦点
                                $$('.pl').focus();
                                //失去焦点弹出层隐藏，绑定发送消息
                                $$(".pl").blur(function (e) {
                                    //发送回复
                                    $$('#sub_tab3 .sendm').on('click', function (e) {
                                        if ($$(".pl").val() == "") return false;
                                        var _conditionParams = "";
                                        var _type = 107;
                                        _conditionParams = JSON.stringify({
                                            type: _type,
                                            comment: {
                                                Code: $$(this).parent().parent().attr('code'),
                                                UserID: iss_localStorage.get("yuqing_appUserId"),
                                                Content: $$(".pl").val()
                                            }
                                        });
                                        var dz = $$(this);
                                        $$.ajax({
                                            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTCOMMENT,
                                            crossDomain: true,
                                            data: { "content": _conditionParams },
                                            method: "POST",
                                            success: function (data, status) {
                                                myApp.alert('点评成功，请等待审核');
                                            },
                                            error: function (xhr, status) {
                                                myApp.alert('点评失败');
                                            }
                                        });
                                    })
                                    setTimeout(function () {
                                        $$(".inputcomment").remove();
                                    }, 200
                                    )

                                });
                            })
                        }
                    }
                },
                error: function (xhr, status) { }
            });

        }
    }

    // 切换
    $$("#footmarklist .subnavbar").on("click", "a", function () {
        $$('.infinite-scroll').scrollTop(0);
        current_tabindex = $$(this).index();
        myApp.attachInfiniteScroll($$('.infinite-scroll'));

        flag_InfiniteScroll = true;
        flag_needScroll = false;

        if ($$(this).index() == 0) {
            LoadStayAll(index_tab1, size);
        }
        else if ($$(this).index() == 1) {
            LoadStayAll(index_tab2, size);
        }
        else if ($$(this).index() == 2) {
            LoadStayAll(index_tab3, size);
        }

    })
})
//详情
var contactsCallback_footmarkdetail = myApp.onPageInit('footmarkdetail', function (page) {
    //获取页面参数
    var para = new Object();
    para.code = ISS.utils.getParameter("code");
    if (page != undefined) {
        para.code = page.query.code;
    }
    para.longitude = ISS.utils.getParameter("longitude");
    if (page != undefined) {
        para.longitude = page.query.longitude;
    }
    para.latitude = ISS.utils.getParameter("latitude");
    if (page != undefined) {
        para.latitude = page.query.latitude;
    }
    para.ctype = ISS.utils.getParameter("ctype");
    if (page != undefined) {
        para.ctype = page.query.ctype;
    }

    //地图初始化要放在地图div隐藏逻辑的前面，不然div隐藏的时候初始化会没有视图
    if (para.longitude != "" && para.latitude != "") {
        var map = new BMap.Map("footmarkMap");
        map.clearOverlays();
        var new_point = new BMap.Point(para.longitude, para.latitude);
        map.centerAndZoom(new_point, 16);
        var marker = new BMap.Marker(new_point);  // 创建标注
        map.addOverlay(marker);              // 将标注添加到地图中
        map.panTo(new_point);
    }

    if (para.ctype == "0") {
        $$('#fmkdetail #footmarkdetail').css('display', "none")
        $$('#fmkdetail .footmark-comment').css('display', "none")
        $$('#fmkdetail #footmarkMap').css('display', "block")
    } else if (para.ctype == "1") {
        $$('#fmkdetail #footmarkMap').css('display', "none")
        $$('#fmkdetail .footmark-comment').css('display', "none")
        $$('#fmkdetail #footmarkdetail').css('display', "block")
    } else if (para.ctype == "3") {
        $$('#fmkdetail #footmarkdetail').css('display', "none")
        $$('#fmkdetail #footmarkMap').css('display', "none")
        $$('#fmkdetail .footmark-comment').css('display', "block")
    }

    $$('#fmkdetail .footmark-sidebar ul li').removeClass("active");
    $$('#fmkdetail .footmark-sidebar ul li').eq(parseInt(para.ctype)).addClass("active");

    var _conditionParams = JSON.stringify({
        type: 1,
        Code: para.code
    });
    $$.ajax({
        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
        crossDomain: true,
        data: { "content": _conditionParams },
        method: "POST",
        success: function (data, status) {
            data = JSON.parse(data);
            console.log(data)
            if (data && data.status == "0" && data.results != null) {
                //详情加载
                var p2html = "";
                data.results.userImage = page.query.userImage;
                var searchTemplate = $$('#fmkdetail #template-footmarkdetail-info').html();
                if (searchTemplate) {
                    var compiledTemplate = Template7.compile(searchTemplate);
                    p2html += compiledTemplate(data.results);
                    $$("#fmkdetail #footmarkdetail").html(p2html);

                    //地图点击
                    $$("#fmkdetail #linemap").on('click', function () {
                        $$('#fmkdetail #footmarkdetail').css('display', "none");
                        $$('#fmkdetail .footmark-comment').css('display', "none");
                        $$('#fmkdetail #footmarkMap').css('display', "block");
                        $$('#fmkdetail .footmark-sidebar ul li').removeClass("active");
                        $$('#fmkdetail .footmark-sidebar ul li').eq(0).addClass("active");
                    })
                    //详情点击
                    $$("#fmkdetail #linedetail").on('click', function () {
                        $$('#fmkdetail #footmarkMap').css('display', "none");
                        $$('#fmkdetail .footmark-comment').css('display', "none");
                        $$('#fmkdetail #footmarkdetail').css('display', "block");
                        $$('#fmkdetail .footmark-sidebar ul li').removeClass("active");
                        $$('#fmkdetail .footmark-sidebar ul li').eq(1).addClass("active");
                    })

                    //图片浏览
                    $$('#fmkdetail .pb-popup').on('click', function (e) {
                        photoview($$('.pb-popup'));
                    })

                }

                //评论加载
                var searchTemplate2 = $$('#fmkdetail #template-footmarkpl-info').html();
                if (searchTemplate2) {
                    var p2html = "";
                    var compiledTemplate = Template7.compile(searchTemplate2);
                    p2html += compiledTemplate(data.results);
                    $$("#fmkdetail .footmark-comment").html(p2html);
                    //评论
                    $$('#fmkdetail #linereply').on('click', function () {
                        $$('#fmkdetail #footmarkdetail').css('display', "none");
                        $$('#fmkdetail #footmarkMap').css('display', "none");
                        $$('#fmkdetail .footmark-comment').css('display', "block");
                        $$('#fmkdetail .footmark-sidebar ul li').removeClass("active");
                        $$('#fmkdetail .footmark-sidebar ul li').eq(3).addClass("active");
                    })
                }


                //图片加载
                var searchTemplate2 = $$('#fmkdetail #template-footmarkph-info').html();
                if (searchTemplate2) {
                    var p2html = "";
                    var compiledTemplate = Template7.compile(searchTemplate2);
                    p2html += compiledTemplate(data.results);
                    $$("#fmkdetail .footmark-album .row").html(p2html);
                    $$("#fmkdetail #lineph").on('click', function () {
                        $$('#fmkdetail .footmark-album').css('display', "block")
                    })
                    $$('#fmkdetail .icon-close').on('click', function () {
                        $$(this).parent().parent().css('display', "none");
                    })
                }


            }
        },
        error: function (xhr, status) { }
    });
});

var contactsCallback_newfootmark_back = myApp.onPageBeforeAnimation('newfootmark', function (page) {
    var poiObj = iss_localStorage.get("yuqing_poi");
    if (poiObj == "") {
        return;
    } else {
        poiObj = JSON.parse(poiObj);
        iss_localStorage.set("yuqing_poi", "");
        var index = poiObj.index;
        var title = poiObj.title;
        var lat = poiObj.lat;
        var lng = poiObj.lng;
        $$("#newfmk #" + index + " .locate").html("<span></span>" + title + "<a href='#' class='skip'></a>");
        $$("#newfmk #" + index + " .locate").attr("lat", lat);
        $$("#newfmk #" + index + " .locate").attr("lng", lng);
    }
});

var imglist;
//添加足迹
var contactsCallback_newfootmark = myApp.onPageInit('newfootmark', function (page) {
    //获取页面参数
    var para = new Object();
    var userID = ISS.utils.getParameter("userID");
    if (userID && userID != undefined && userID != null && userID != "") {
        iss_localStorage.set("yuqing_appUserId", userID);
    } else {
        userID = iss_localStorage.get("yuqing_appUserId");
    }
    
    imglist = new Array();
    para.code = ISS.utils.getParameter("code");
    if (page != undefined) {
        para.code = page.query.code;
    }

    sessionStorage.left = 0;
    sessionStorage.pagecount = "第一天";
    
    if (para.code != "" && para.code != undefined) {
        loadmyfoot(para.code);
    } else {
        //日期控件初始化
        loadDatepicker(ISS.utils.dateToStr("yyyy-MM-dd", new Date()));
        loadDatepicker1(ISS.utils.dateToStr("yyyy-MM-dd", new Date()));
        loadDatepicker2(ISS.utils.dateToStr("yyyy-MM-dd", new Date()));
        loadDatepicker3(ISS.utils.dateToStr("yyyy-MM-dd", new Date()));
        loadDatepicker4(ISS.utils.dateToStr("yyyy-MM-dd", new Date()));

        //TAB切换效果
        tab();
        //添加天数
        addDay();

        //获取当前定位位置
        getAddress();
        $$('#newfmk .right').on('click', function () {
            var theme = new Object();
            theme.Title = "";
            theme.UserID = userID;
            theme.CreateTime = $$('.year').attr('date');
            theme.ShowList = new Array();
            $$('#newfmk .find_nav_list li').each(function (i, v) {
                var id = "#new" + i;
                if ($$(id).length != 0 && $$(id).find('.item-input input').val() != "") {
                    var obj = new Object()
                    if ($$(id).find('.locate').attr('lng') == undefined || $$(id).find('.locate').attr('lng') == "") {
                        obj.Longitude = iss_localStorage.get("yuqing_longitude");
                        obj.Address = iss_localStorage.get("yuqing_current_address");
                    } else {
                        obj.Longitude = $$(id).find('.locate').attr('lng');
                        obj.Address = $$(id).find('.locate').text();
                    }

                    if ($$(id).find('.locate').attr('lat') == undefined || $$(id).find('.locate').attr('lat') == "") {
                        obj.Latitude = iss_localStorage.get("yuqing_latitude");
                    } else {
                        obj.Latitude = $$(id).find('.locate').attr('lat');
                    }

                    obj.CreateTime = $$(id).find('.year').attr('date')
                    obj.Content = $$(id).find('.item-input input').val();
                    obj.Sort = i + 1;
                    theme.ShowList.push(obj)
                }
            })
            if (theme.ShowList.length <= 0) {
                myApp.alert("请编辑发布内容再进行发布！");
                return;
            }
            // JSON
            var _conditionParams = JSON.stringify({
                type: 111,
                theme: theme
            });
            myApp.showPreloader("发布中...");
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKTHEME,
                crossDomain: true,
                data: { "content": _conditionParams, "imageList": JSON.stringify(imglist) },
                method: "POST",
                success: function (data, status) {
                    myApp.hidePreloader();
                    data = JSON.parse(data);
                    console.log(data);
                    if (data && data.status == "0") {
                        //成功
                        myApp.alert('发布成功');
                        mainView.router.back();
                        //手动加载新的数据
                        var _conditionParams = JSON.stringify({
                            type: 0,
                            UserID: iss_localStorage.get("yuqing_appUserId"),
                            BookType: 3,
                            pageIndex: 1,
                            pageSize: 10
                        });
                        $$.ajax({
                            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                            crossDomain: true,
                            data: { "content": _conditionParams },
                            method: "POST",
                            success: function (data, status) {
                                data = JSON.parse(data);
                                console.log(data);
                                if (data && data.status == "0" && data.results.length > 0) {
                                    var p2html = "";
                                    var searchTemplate = $$('#template-footmarklist-myinfo').html();
                                    if (searchTemplate) {
                                        var compiledTemplate = Template7.compile(searchTemplate);
                                        p2html += compiledTemplate(data);
                                        $$("#footmarklist #sub_tab3 .page-content ul").html(p2html);
                                        //默认隐藏多篇日记
                                        $$('#footmarklist #sub_tab3 .footmark-card').each(function () {
                                            $$(this).find('.footmark-list').each(function (i, v) {
                                                if (i != 0) {
                                                    $$(this).css('display', 'none')
                                                }
                                            })
                                        })
                                        //展开或者收起日记
                                        $$('#footmarklist #sub_tab3 .footmark-tool').on('click', function () {
                                            var tool = $$(this);
                                            $$(this).parent().parent().find('.footmark-list').each(function (i, k) {
                                                if (i != 0 && tool.text() == "收起") {
                                                    $$(this).removeAttr('style')
                                                    $$(this).css('display', 'none')
                                                } else if (i != 0 && tool.text() == "展开") {
                                                    $$(this).removeAttr('style')
                                                    $$(this).css('display', 'block')
                                                }
                                            })
                                            if (tool.text() == "收起") {
                                                tool.find('.close').html('展开 <i class="iconfont icon-jiantou-down"></i>')
                                            } else {
                                                tool.find('.close').html('收起 <i class="iconfont icon-jiantou-up"></i>')
                                            }
                                        })
                                        //点赞
                                        $$('#footmarklist #sub_tab3 .active').on('click', function () {
                                            var _conditionParams = "";
                                            var _type = $$(this).attr("islike") == "1" ? 102 : 101;
                                            _conditionParams = JSON.stringify({
                                                type: _type,
                                                like: {
                                                    Code: $$(this).attr('code'),
                                                    UserID: iss_localStorage.get("yuqing_appUserId"),
                                                }
                                            });
                                            var dz = $$(this);
                                            $$.ajax({
                                                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKLIKE,
                                                crossDomain: true,
                                                data: { "content": _conditionParams },
                                                method: "POST",
                                                success: function (data, status) {
                                                    var jdata = JSON.parse(data).results;
                                                    if (_type == 102) {
                                                        dz.attr("islike", "0");
                                                        dz.find('i').removeClass("icon-zan");
                                                        dz.find('i').addClass("icon-zank");
                                                        var likecount = parseInt(dz.find(".likecount").html()) - 1;
                                                        dz.find(".likecount").html(likecount);
                                                    } else {
                                                        dz.attr("islike", "1");
                                                        dz.find('i').removeClass("icon-zank");
                                                        dz.find('i').addClass("icon-zan");
                                                        var likecount = parseInt(dz.find(".likecount").html()) + 1;
                                                        dz.find(".likecount").html(likecount);
                                                    }
                                                },
                                                error: function (xhr, status) {
                                                    myApp.alert("点赞失败！");
                                                }
                                            });
                                        })
                                        //图片浏览
                                        $$('#footmarklist #sub_tab3 .pic-box').on('click', function (e) {
                                            photoview($$(this).find('div'));
                                            e.preventDefault();
                                        })
                                        //删除
                                        $$('#footmarklist #sub_tab3 .delete').on('click', function () {
                                            var _conditionParams = "";
                                            var _type = 105;
                                            _conditionParams = JSON.stringify({
                                                type: _type,
                                                Code: $$(this).attr('code'),
                                                UserID: iss_localStorage.get("yuqing_appUserId")
                                            });
                                            var dz = $$(this);
                                            $$.ajax({
                                                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                                                crossDomain: true,
                                                data: { "content": _conditionParams },
                                                method: "POST",
                                                success: function (data, status) {
                                                    var status = JSON.parse(data).status;
                                                    if (status == 0) {
                                                        dz.parent().parent().parent().remove();
                                                        myApp.alert('删除成功');
                                                    } else {
                                                        myApp.alert('删除异常');
                                                    }
                                                },
                                                error: function (xhr, status) { }
                                            });
                                        })
                                        //弹出回复
                                        $$('#footmarklist #sub_tab3 .comment-enter').on('click', function (e) {
                                            $(this).parent().after('<div class="inputcomment" code="' + $$(this).parent().attr('code') + '" style="width:100%;position: absolute;"><div class="item-input" style="background-color: #f9f9f9;padding: 6px;border-top: 0.2px solid #d8d8d8;"><input class="pl" type="text" name="comment"placeholder="评论"style="width: 80%;height: 25px;border: 1px solid #f2f2f2;padding: 0 8px;"><a class="sendm" href="#" style="width: 15%;font-size: 12px;margin-left: 10px;">发送</a></div></div>')
                                            //键盘弹起不遮挡输入框
                                            var target = $$('.pl');
                                            setTimeout(function () {
                                                target.scrollIntoViewIfNeeded();
                                            }, 100);

                                            if (/Android [4-6]/.test(navigator.appVersion)) {
                                                window.addEventListener("resize", function () {
                                                    if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
                                                        window.setTimeout(function () {
                                                            document.activeElement.scrollIntoViewIfNeeded();
                                                        }, 0);
                                                    }
                                                })
                                            }
                                            //得到焦点
                                            $$('.pl').focus();
                                            //失去焦点弹出层隐藏，绑定发送消息
                                            $$(".pl").blur(function (e) {
                                                //发送回复
                                                $$('#sub_tab3 .sendm').on('click', function (e) {
                                                    if ($$(".pl").val() == "") return false;
                                                    var _conditionParams = "";
                                                    var _type = 107;
                                                    _conditionParams = JSON.stringify({
                                                        type: _type,
                                                        comment: {
                                                            Code: $$(this).parent().parent().attr('code'),
                                                            UserID: iss_localStorage.get("yuqing_appUserId"),
                                                            Content: $$(".pl").val()
                                                        }
                                                    });
                                                    var dz = $$(this);
                                                    $$.ajax({
                                                        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTCOMMENT,
                                                        crossDomain: true,
                                                        data: { "content": _conditionParams },
                                                        method: "POST",
                                                        success: function (data, status) {
                                                            myApp.alert('点评成功，请等待审核');
                                                        },
                                                        error: function (xhr, status) {
                                                            myApp.alert('点评失败');
                                                        }
                                                    });
                                                })
                                                setTimeout(function () {
                                                    $$(".inputcomment").remove();
                                                }, 200
                                                )

                                            });
                                        })
                                    }
                                }
                            },
                            error: function (xhr, status) { }
                        });

                    } else {
                        myApp.alert('服务器累了，请稍后发布');
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert("服务器连接失败！")
                }
            });
        })
    }

    //每天加载图片
    $('#newfmk #edit-img0').on("change", "input[type='file']", function () {
        var imgs = $(this).parent().parent().parent().find("#upload-container0 div")
        // if (imgs.length >= 4) {
        //     myApp.alert("最多只能上传4张照片");
        //     return;
        // }
        var that = $(this);
        if (imgs.length + that[0].files.length > 4) {
            myApp.alert("最多只能上传4张照片");
            return;
        }
        for (var i = 0; i < that[0].files.length; i++) {
            lrz(that[0].files[i], {
                quality: 0.6 //图片质量  
            })
                .then(function (rst) {
                    var img = new Image();
                    var div = document.createElement('div');
                    div.className = 'col-33';
                    div.innerHTML = '<img class="delete" src="../../assets/images/base/delete_img.png" style="position:absolute;width:20px;height:20px;right:0;top:0;"/>';
                    $(div).css("position", "relative");
                    $(div).css("background-image", "url(" + rst.base64 + ")");
                    //$$(div).attr("FileName", rst.origin.name);
                    //$$(div).attr("type", rst.origin.type);
                    //$$(div).attr("data", rst.base64);
                    var obj = new Object();
                    if (imglist.length == 0) {
                        obj.FileName = "site_1_1.jpg";
                        obj.type = rst.origin.type;
                        obj.img = rst.base64;
                    } else {
                        obj.FileName = isexistimgname("site_1_{0}.jpg", imglist.length + 1);
                        obj.type = rst.origin.type
                        obj.img = rst.base64
                    }
                    $(div).attr("filename", obj.FileName);
                    imglist.push(obj);
                    $(div).find(".delete").on("click", function () {
                        var filename = $$(this).parent().attr("filename");
                        $$(this).parents(".col-33").remove();
                        for (var j = 0; j < imglist.length; j++) {
                            if (imglist[j].FileName == filename) {
                                imglist.splice(j, 1);
                            }
                        }
                    });
                    $('#upload-container0').append(div);
                });
        }
    })
    $('#newfmk #edit-img1').on("change", "input[type='file']", function () {
        var imgs = $(this).parent().parent().parent().find("#upload-container1 div");
        var that = $(this);
        if (imgs.length + that[0].files.length > 4) {
            myApp.alert("最多只能上传4张照片");
            return;
        }

        for (var i = 0; i < that[0].files.length; i++) {
            lrz(that[0].files[i], {
                quality: 0.6 //图片质量  
            })
                .then(function (rst) {
                    var img = new Image();
                    var div = document.createElement('div');
                    div.className = 'col-33';
                    div.innerHTML = '<img class="delete" src="../../assets/images/base/delete_img.png" style="position:absolute;width:20px;height:20px;right:0;top:0;"/>';
                    $(div).css("position", "relative");
                    $(div).css("background-image", "url(" + rst.base64 + ")");
                    //$$(div).attr("FileName", rst.origin.name);
                    //$$(div).attr("type", rst.origin.type);
                    //$$(div).attr("data", rst.base64);
                    var obj = new Object();
                    if (imglist.length == 0) {
                        obj.FileName = "site_2_1.jpg";
                        obj.type = rst.origin.type;
                        obj.img = rst.base64;
                    } else {
                        obj.FileName = isexistimgname("site_2_{0}.jpg", imglist.length + 1); //"site_2_" + (imglist.length + 1) + ".jpg"
                        obj.type = rst.origin.type
                        obj.img = rst.base64
                    }
                    $(div).attr("filename", obj.FileName);
                    imglist.push(obj);
                    $(div).find(".delete").on("click", function () {
                        var filename = $$(this).parent().attr("filename");
                        $$(this).parents(".col-33").remove();
                        for (var j = 0; j < imglist.length; j++) {
                            if (imglist[j].FileName == filename) {
                                imglist.splice(j, 1);
                            }
                        }
                    });
                    $('#upload-container1').append(div);
                });
        }
    })
    $('#newfmk #edit-img2').on("change", "input[type='file']", function () {
        var imgs = $(this).parent().parent().parent().find("#upload-container2 div");
        var that = $(this);
        if (imgs.length + that[0].files.length > 4) {
            myApp.alert("最多只能上传4张照片");
            return;
        }

        for (var i = 0; i < that[0].files.length; i++) {
            lrz(that[0].files[i], {
                quality: 0.6 //图片质量  
            })
                .then(function (rst) {

                    var img = new Image();
                    var div = document.createElement('div');
                    div.className = 'col-33';
                    div.innerHTML = '<img class="delete" src="../../assets/images/base/delete_img.png" style="position:absolute;width:20px;height:20px;right:0;top:0;"/>';
                    $(div).css("position", "relative");
                    $(div).css("background-image", "url(" + rst.base64 + ")");
                    //$$(div).attr("FileName", rst.origin.name);
                    //$$(div).attr("type", rst.origin.type);
                    //$$(div).attr("data", rst.base64);
                    var obj = new Object();
                    if (imglist.length == 0) {
                        obj.FileName = "site_3_1.jpg";
                        obj.type = rst.origin.type;
                        obj.img = rst.base64;
                    } else {
                        obj.FileName = isexistimgname("site_3_{0}.jpg", imglist.length + 1); //"site_3_" + (imglist.length + 1) + ".jpg"
                        obj.type = rst.origin.type
                        obj.img = rst.base64
                    }
                    $(div).attr("filename", obj.FileName);
                    imglist.push(obj);
                    $(div).find(".delete").on("click", function () {
                        var filename = $$(this).parent().attr("filename");
                        $$(this).parents(".col-33").remove();
                        for (var j = 0; j < imglist.length; j++) {
                            if (imglist[j].FileName == filename) {
                                imglist.splice(j, 1);
                            }
                        }
                    });
                    $('#upload-container2').append(div);
                });
        }
    })
    $('#newfmk #edit-img3').on("change", "input[type='file']", function () {
        var imgs = $(this).parent().parent().parent().find("#upload-container3 div");
        var that = $(this);
        if (imgs.length + that[0].files.length > 4) {
            myApp.alert("最多只能上传4张照片");
            return;
        }

        for (var i = 0; i < that[0].files.length; i++) {
            lrz(that[0].files[i], {
                quality: 0.6 //图片质量  
            })
                .then(function (rst) {

                    var img = new Image();
                    var div = document.createElement('div');
                    div.className = 'col-33';
                    div.innerHTML = '<img class="delete" src="../../assets/images/base/delete_img.png" style="position:absolute;width:20px;height:20px;right:0;top:0;"/>';
                    $(div).css("position", "relative");
                    $(div).css("background-image", "url(" + rst.base64 + ")");
                    //$$(div).attr("FileName", rst.origin.name);
                    //$$(div).attr("type", rst.origin.type);
                    //$$(div).attr("data", rst.base64);
                    var obj = new Object();
                    if (imglist.length == 0) {
                        obj.FileName = "site_4_1.jpg";
                        obj.type = rst.origin.type;
                        obj.img = rst.base64;
                    } else {
                        obj.FileName = isexistimgname("site_4_{0}.jpg", imglist.length + 1); //"site_4_" + (imglist.length + 1) + ".jpg"
                        obj.type = rst.origin.type
                        obj.img = rst.base64
                    }
                    $(div).attr("filename", obj.FileName);
                    imglist.push(obj);
                    $(div).find(".delete").on("click", function () {
                        var filename = $$(this).parent().attr("filename");
                        $$(this).parents(".col-33").remove();
                        for (var j = 0; j < imglist.length; j++) {
                            if (imglist[j].FileName == filename) {
                                imglist.splice(j, 1);
                            }
                        }
                    });
                    $('#upload-container3').append(div);
                });
        }
    })
    $('#newfmk #edit-img4').on("change", "input[type='file']", function () {
        var imgs = $(this).parent().parent().parent().find("#upload-container4 div");
        var that = $(this);
        if (imgs.length + that[0].files.length > 4) {
            myApp.alert("最多只能上传4张照片");
            return;
        }

        for (var i = 0; i < that[0].files.length; i++) {
            lrz(that[0].files[i], {
                quality: 0.6 //图片质量  
            })
                .then(function (rst) {

                    var img = new Image();
                    var div = document.createElement('div');
                    div.className = 'col-33';
                    div.innerHTML = '<img class="delete" src="../../assets/images/base/delete_img.png" style="position:absolute;width:20px;height:20px;right:0;top:0;"/>';
                    $(div).css("position", "relative");
                    $(div).css("background-image", "url(" + rst.base64 + ")");
                    //$$(div).attr("FileName", rst.origin.name);
                    //$$(div).attr("type", rst.origin.type);
                    //$$(div).attr("data", rst.base64);
                    var obj = new Object();
                    if (imglist.length == 0) {
                        obj.FileName = "site_5_1.jpg";
                        obj.type = rst.origin.type;
                        obj.img = rst.base64;
                    } else {
                        obj.FileName = isexistimgname("site_5_{0}.jpg", imglist.length + 1); // "site_5_" + (imglist.length + 1) + ".jpg"
                        obj.type = rst.origin.type
                        obj.img = rst.base64
                    }
                    $(div).attr("filename", obj.FileName);
                    imglist.push(obj);
                    $(div).find(".delete").on("click", function () {
                        var filename = $$(this).parent().attr("filename");
                        $$(this).parents(".col-33").remove();
                        for (var j = 0; j < imglist.length; j++) {
                            if (imglist[j].FileName == filename) {
                                imglist.splice(j, 1);
                            }
                        }
                    });
                    $('#upload-container4').append(div);
                });
        }
    })

    //是否重复名字
    function isexistimgname(name, k) {
        var str = name.format(k);
        var isexist = false;
        for (var y = 0; y < imglist.length; y++) {
            if (imglist[y].FileName == str) {
                isexistimgname(name, ++k);
            }
        }

        return str;
    }
    //加载个人足迹
    function loadmyfoot(code) {
        var _conditionParams = JSON.stringify({
            type: 1,
            Code: code
        });
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
            crossDomain: true,
            data: { "content": _conditionParams },
            method: "POST",
            success: function (data, status) {
                data = JSON.parse(data);
                console.log(data)
                if (data && data.status == "0" && data.results != null) {
                    $$('.locate').attr('lat', iss_localStorage.get("yuqing_latitude"));
                    $$('.locate').attr('lng', iss_localStorage.get("yuqing_longitude"));
                    $$('.locate').html("<span></span>" + iss_localStorage.get("yuqing_current_address") + "<a href='#' class='skip'></a>")

                    var times = [new Date(), new Date(), new Date(), new Date(), new Date()];
                    for (var i = 0; i < data.results.ShowList.length; i++) {
                        var id = "#new" + i;
                        var obj = data.results.ShowList[i];
                        $$(id).find('.item-input input').val(obj.Content);
                        $$(id).find('.year').attr('date', obj.CreateTime);
                        $$(id + " .locate").attr('lat', obj.Latitude);
                        $$(id + " .locate").attr('lng', obj.Longitude);
                        $$(id + " .locate").html("<span></span>" + obj.Address + "<a href='#' class='skip'></a>")
                        times[i] = obj.CreateTime.substring(0,obj.CreateTime.indexOf(' '));
                        for (var j = 0; j < obj.GetImage.ImageList.length; j++) {
                            var imgobj = obj.GetImage.ImageList[j];
                            var div = document.createElement('div');
                            div.className = 'col-33';
                            $(div).attr('PicID', imgobj.PicID);
                            var url = imgobj.MiddleImgSrc;
                            div.innerHTML = '<img class="delete" src="../../assets/images/base/delete_img.png" style="position:absolute;width:20px;height:20px;right:0;top:0;"/>';
                            $(div).css("position", "relative");
                            $(div).css("background-image", "url(" + url + ")");
                            $(div).find(".delete").on("click", function () {
                                $$(this).parents(".col-33").remove();
                            });
                            $('#upload-container' + i).append(div);
                        }
                    }

                    for (var i = 1; i < data.results.ShowList.length; i++) {
                        var ul = $$('.find_nav_list ul');
                        if (i < 5) {
                            var dayName = "";
                            if (i == 1) {
                                dayName = "第二天";
                            } else if (i == 2) {
                                dayName = "第三天";
                            } else if (i == 3) {
                                dayName = "第四天";
                            } else if (i == 4) {
                                dayName = "第五天";
                            }
                            $("<li id='" + i + "' class='dayTab'><a href='#'>" + dayName + "</a><span></span></li>").insertBefore(".addli");
                            ul.find('.dayTab').eq(i).on("click", "span", function () {
                                delDay(parseInt($$(this).parent().attr("id")));
                            });
                            if (ul.find('.dayTab').length == 5) {
                                $$(this).remove();
                            }
                        }
                    }
                    //TAB切换效果
                    tab();
                    //添加天数
                    addDay();

                    //日期控件初始化
                    loadDatepicker(times[0]);
                    loadDatepicker1(times[1]);
                    loadDatepicker2(times[2]);
                    loadDatepicker3(times[3]);
                    loadDatepicker4(times[4]);

                    $$('.locate').each(function () {
                        $$(this).on("click", function () {
                            mainView.router.load({ url: '../../view/footmark/locationSelect.html?lat=' + $$(this).attr("lat") + "&lng=" + $$(this).attr("lng") + "&index=" + $$(this).parent().attr("id"), reload: false });
                        });
                    });
                    editfoormark(code);
                }
            },
            error: function (xhr, status) { }
        });
    }
    //修改足迹
    function editfoormark(code) {
        $$('#newfmk .right').on('click', function () {
            var theme = new Object();
            var themePartList = new Object();
            var userID = ISS.utils.getParameter("userID");
            if (userID && userID != undefined && userID != null && userID != "") {
                iss_localStorage.set("yuqing_appUserId", userID);
            } else {
                userID = iss_localStorage.get("yuqing_appUserId");
            }
            theme.Code = code;
            theme.Title = "";
            theme.UserID = userID;
            theme.CreateTime = $$('.year').attr('date');
            theme.ShowList = new Array();
            var themePartList = new Array();
            $$('#newfmk .find_nav_list li').each(function (i, v) {
                var id = "#new" + i;
                if ($$(id).length != 0 && $$(id).find('.item-input input').val() != "") {
                    var obj = new Object()
                    obj.Longitude = $$(id).find('.locate').attr('lng');
                    obj.Address = $$(id).find('.locate').text();
                    obj.Latitude = $$(id).find('.locate').attr('lat');
                    obj.CreateTime = $$(id).find('.year').attr('date')
                    obj.Content = $$(id).find('.item-input input').val();
                    obj.Sort = i + 1;
                    theme.ShowList.push(obj)
                    //已有图片
                    existimg = new Array();
                    //新加图片
                    newimg = new Array();

                    $$(id + " .col-33").each(function (i, v) {
                        if (typeof ($(v).attr('picId')) != 'undefined') {
                            existimg.push($(v).attr('picId'));
                        }
                    })
                    if (existimg.length > 0) {
                        var themePart = new Object();
                        themePart.index = i;
                        themePart.picIdList = existimg;
                        themePartList.push(themePart);
                    }
                }
            })

            if (theme.ShowList.length <= 0) {
                myApp.alert("请编辑发布内容再进行发布！");
                return;
            }

            // JSON
            var _conditionParams = JSON.stringify({
                type: 104,
                theme: theme,
                themePartList: themePartList
            });
            myApp.showPreloader("发布中....");
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKTHEME,
                crossDomain: true,
                data: { "content": _conditionParams, "imageList": JSON.stringify(imglist) },
                method: "POST",
                success: function (data, status) {
                    myApp.hidePreloader();
                    data = JSON.parse(data);
                    console.log(data);
                    if (data && data.status == "0") {
                        //成功
                        myApp.alert('发布成功');
                        mainView.router.back();
                        //手动加载新的数据
                        var _conditionParams = JSON.stringify({
                            type: 0,
                            UserID: iss_localStorage.get("yuqing_appUserId"),
                            BookType: 3,
                            pageIndex: 1,
                            pageSize: 10
                        });
                        $$.ajax({
                            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                            crossDomain: true,
                            data: { "content": _conditionParams },
                            method: "POST",
                            success: function (data, status) {
                                data = JSON.parse(data);
                                console.log(data);
                                if (data && data.status == "0" && data.results.length > 0) {
                                    var searchTemplate = $$('#template-footmarklist-myinfo').html();
                                    if (searchTemplate) {
                                        var p2html = "";
                                        var compiledTemplate = Template7.compile(searchTemplate);
                                        p2html += compiledTemplate(data);
                                        $$("#footmarklist #sub_tab3 .page-content ul").html(p2html);
                                        //默认隐藏多篇日记
                                        $$('#footmarklist #sub_tab3 .footmark-card').each(function () {
                                            $$(this).find('.footmark-list').each(function (i, v) {
                                                if (i != 0) {
                                                    $$(this).css('display', 'none')
                                                }
                                            })
                                        })
                                        //展开或者收起日记
                                        $$('#footmarklist #sub_tab3 .footmark-tool').on('click', function () {
                                            var tool = $$(this);
                                            $$(this).parent().parent().find('.footmark-list').each(function (i, k) {
                                                if (i != 0 && tool.text() == "收起") {
                                                    $$(this).removeAttr('style')
                                                    $$(this).css('display', 'none')
                                                } else if (i != 0 && tool.text() == "展开") {
                                                    $$(this).removeAttr('style')
                                                    $$(this).css('display', 'block')
                                                }
                                            })
                                            if (tool.text() == "收起") {
                                                tool.find('.close').html('展开 <i class="iconfont icon-jiantou-down"></i>')
                                            } else {
                                                tool.find('.close').html('收起 <i class="iconfont icon-jiantou-up"></i>')
                                            }
                                        })
                                        //点赞
                                        $$('#footmarklist #sub_tab3 .active').on('click', function () {
                                            var _conditionParams = "";
                                            var _type = $$(this).attr("islike") == "1" ? 102 : 101;
                                            _conditionParams = JSON.stringify({
                                                type: _type,
                                                like: {
                                                    Code: $$(this).attr('code'),
                                                    UserID: iss_localStorage.get("yuqing_appUserId"),

                                                }
                                            });
                                            var dz = $$(this);
                                            $$.ajax({
                                                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARKLIKE,
                                                crossDomain: true,
                                                data: { "content": _conditionParams },
                                                method: "POST",
                                                success: function (data, status) {
                                                    var jdata = JSON.parse(data).results;
                                                    if (_type == 102) {
                                                        dz.attr("islike", "0");
                                                        dz.find('i').removeClass("icon-zan");
                                                        dz.find('i').addClass("icon-zank");
                                                        var likecount = parseInt(dz.find(".likecount").html()) - 1;
                                                        dz.find(".likecount").html(likecount);
                                                    } else {
                                                        dz.attr("islike", "1");
                                                        dz.find('i').removeClass("icon-zank");
                                                        dz.find('i').addClass("icon-zan");
                                                        var likecount = parseInt(dz.find(".likecount").html()) + 1;
                                                        dz.find(".likecount").html(likecount);
                                                    }
                                                },
                                                error: function (xhr, status) {
                                                    myApp.alert("点赞失败！");
                                                }
                                            });
                                        })
                                        //图片浏览
                                        $$('#footmarklist #sub_tab3 .pic-box').on('click', function (e) {
                                            photoview($$(this).find('div'));
                                            e.preventDefault();
                                        })
                                        //删除
                                        $$('#footmarklist #sub_tab3 .delete').on('click', function () {
                                            var _conditionParams = "";
                                            var _type = 105;
                                            _conditionParams = JSON.stringify({
                                                type: _type,
                                                Code: $$(this).attr('code'),
                                                UserID: iss_localStorage.get("yuqing_appUserId")
                                            });
                                            var dz = $$(this);
                                            $$.ajax({
                                                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTMARK,
                                                crossDomain: true,
                                                data: { "content": _conditionParams },
                                                method: "POST",
                                                success: function (data, status) {
                                                    var status = JSON.parse(data).status;
                                                    if (status == 0) {
                                                        dz.parent().parent().parent().remove();
                                                        myApp.alert('删除成功');
                                                    } else {
                                                        myApp.alert('删除异常');
                                                    }
                                                },
                                                error: function (xhr, status) { }
                                            });
                                        })
                                        //弹出回复
                                        $$('#footmarklist #sub_tab3 .comment-enter').on('click', function (e) {
                                            $(this).parent().after('<div class="inputcomment" code="' + $$(this).parent().attr('code') + '" style="width:100%;position: absolute;"><div class="item-input" style="background-color: #f9f9f9;padding: 6px;border-top: 0.2px solid #d8d8d8;"><input class="pl" type="text" name="comment"placeholder="评论"style="width: 80%;height: 25px;border: 1px solid #f2f2f2;padding: 0 8px;"><a class="sendm" href="#" style="width: 15%;font-size: 12px;margin-left: 10px;">发送</a></div></div>')
                                            //键盘弹起不遮挡输入框
                                            var target = $$('.pl');
                                            setTimeout(function () {
                                                target.scrollIntoViewIfNeeded();
                                            }, 100);

                                            if (/Android [4-6]/.test(navigator.appVersion)) {
                                                window.addEventListener("resize", function () {
                                                    if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
                                                        window.setTimeout(function () {
                                                            document.activeElement.scrollIntoViewIfNeeded();
                                                        }, 0);
                                                    }
                                                })
                                            }
                                            //得到焦点
                                            $$('.pl').focus();
                                            //失去焦点弹出层隐藏，绑定发送消息
                                            $$(".pl").blur(function (e) {
                                                //发送回复
                                                $$('#sub_tab3 .sendm').on('click', function (e) {
                                                    if ($$(".pl").val() == "") return false;
                                                    var _conditionParams = "";
                                                    var _type = 107;
                                                    _conditionParams = JSON.stringify({
                                                        type: _type,
                                                        comment: {
                                                            Code: $$(this).parent().parent().attr('code'),
                                                            UserID: iss_localStorage.get("yuqing_appUserId"),
                                                            Content: $$(".pl").val()
                                                        }
                                                    });
                                                    var dz = $$(this);
                                                    $$.ajax({
                                                        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.FOOTCOMMENT,
                                                        crossDomain: true,
                                                        data: { "content": _conditionParams },
                                                        method: "POST",
                                                        success: function (data, status) {
                                                            myApp.alert('点评成功，请等待审核');
                                                        },
                                                        error: function (xhr, status) {
                                                            myApp.alert('点评失败');
                                                        }
                                                    });
                                                })
                                                setTimeout(function () {
                                                    $$(".inputcomment").remove();
                                                }, 200
                                                )

                                            });
                                        })
                                    }
                                }
                            },
                            error: function (xhr, status) { }
                        });

                    } else {
                        myApp.alert('服务器累了，请稍后发布');
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert("服务器连接失败！");
                }
            });
        })
    }
})

//添加天数实现
var addDay = function () {
    $$('#newfmk .addli').on('click', function () {
        var ul = $$('.find_nav_list ul');
        var currentIndex = ul.find('.dayTab').length;
        if (ul.find('.dayTab').length < 5) {
            var dayName = "";
            if (ul.find('.dayTab').length == 1) {
                dayName = "第二天";
            } else if (ul.find('.dayTab').length == 2) {
                dayName = "第三天";
            } else if (ul.find('.dayTab').length == 3) {
                dayName = "第四天";
            } else if (ul.find('.dayTab').length == 4) {
                dayName = "第五天";
            }

            $("<li id='" + currentIndex + "'  class='dayTab'><a href='#'>" + dayName + "</a><span></span></li>").insertBefore(".addli");
            sessionStorage.pagecount = currentIndex + "";
            tab();
            ul.find('.dayTab').eq(currentIndex).on("click", "span", function () {
                delDay(parseInt($$(this).parent().attr("id")));
            });
            if (ul.find('.dayTab').length == 5) {
                $$(this).remove();
            }
        }
    })
}

//删除天数实现
var delDay = function (index) {
    $$("#newfmk .find_nav_list .dayTab").eq(index).remove();
    var totalnumber = $$("#newfmk .find_nav_list .dayTab").length;
    $$("#newfmk .find_nav_list ul").html("");
    for (var i = 0; i < totalnumber; i++) {
        var dayName = "";
        switch (i) {
            case 0:
                dayName = "第一天";
                break;
            case 1:
                dayName = "第二天";
                break;
            case 2:
                dayName = "第三天";
                break;
            case 3:
                dayName = "第四天";
                break;
        }
        var html = "";
        if (i == 0) {
            html = "<li id='" + i + "' class='dayTab'><a href='#'>" + dayName + "</a></li>";
        } else {
            html = "<li id='" + i + "' class='dayTab'><a href='#'>" + dayName + "</a><span></span></li>";
        }
        $$("#newfmk .find_nav_list ul").append(html);
    }
    if ($$("#newfmk .find_nav_list .addli").length == 0) {
        $$("#newfmk .find_nav_list ul").append("<li class='addli'><a href='#'><span class='addDay'></span></a></li>");
        addDay();
    }

    $$("#newfmk .find_nav_list .dayTab").each(function () {
        $$(this).on("click", "span", function () {
            delDay(parseInt($$(this).parent().attr("id")));
        })
    })

    sessionStorage.pagecount = "0";
    tab();

    //重置每天数据
    initPerData(index);
}

var initPerData = function (index) {
    var data = [];
    $$("#newfmk .page-content .publish").each(function () {
        var obj = {
            content: $$(this).find(".item-input input").val(),
            imgdata: $$(this).find(".show .upload-container .row").html(),
            lat: $$(this).find(".locate").attr("lat"),
            lng: $$(this).find(".locate").attr("lng"),
            locate: $$(this).find(".locate").html(),
            time: $$(this).find(".time-select .year").attr("date")
        };
        data[data.length] = obj;
    });

    for (var i = index; i < 4; i++) {
        var day = $$("#newfmk .page-content .publish").eq(i);
        var obj = data[i + 1];
        day.find(".item-input input").val(obj.content);
        day.find(".show .upload-container .row").html(obj.imgdata);
        day.find(".locate").attr("lat", obj.lat);
        day.find(".locate").attr("lng", obj.lng);
        day.find(".locate").html(obj.locate);
        day.find(".time-select .year").attr("date", obj.time);
        day.find(".time-select .year").html(obj.time.substring(0, 4) + "年 " + obj.time.substring(5, 7) + "月 " + obj.time.substring(8, 10) + "日" + "<i class='iconfont icon-jiantou'></i>");
    }

    day = $$("#newfmk .page-content .publish").eq(4);
    day.find(".item-input input").val("");
    day.find(".show .upload-container .row").html("");
    day.find(".locate").attr("lat", iss_localStorage.get("yuqing_latitude"));
    day.find(".locate").attr("lng", iss_localStorage.get("yuqing_longitude"));
    day.find(".locate").html(iss_localStorage.get("yuqing_current_address"));

    var myDate = new Date();
    var nowy = myDate.getFullYear(); //当前年
    var nowm = myDate.getMonth() + 1; //当前月
    var nowd = myDate.getDate(); //当前日
    var datettml = nowy + "年 ";
    datettml += checkTime(nowm) + "月 ";
    datettml += checkTime(nowd) + "日";
    datettml += '<i class="iconfont icon-jiantou"></i>';

    day.find(".time-select .year").attr("date", nowy + "-" + checkTime(nowm) + "-" + checkTime(nowd));
    day.find(".time-select .year").html(datettml);

    for(var i=0;i<imglist.length;i++){
        var day=parseInt(imglist[i].FileName.substring(5,6));
        if(day==index+1){
            imglist.splice(i,1);
            i--;
        }
    }

    for(var i=0;i<imglist.length;i++){
        var day=parseInt(imglist[i].FileName.substring(5,6));
        if(day>index){
            var arr=imglist[i].FileName.split("");
            arr.splice(5,1,--day);
            imglist[i].FileName=arr.join("");
        }
    }
}


function photoview(picbox) {
    var arr = new Array()
    picbox.each(function () {
        arr.push($$(this).attr('imgurl'))
    })
    if (arr.length > 0) {
        var myPhotoBrowserPopup = myApp.photoBrowser({
            photos: arr,
            type: 'popup',
            zoom: true,
            exposition: true,
            navbar: true,
            backLinkText: "返回",
            ofText: " / ",
            theme: 'dark',
        });
        myPhotoBrowserPopup.open();
    }
}

function initData() {
    var href = window.location.href;
    if (href.indexOf(footmarklist) > -1) {
        contactsCallback_footmarklist.trigger();
    } else if (href.indexOf(footmarkdetail) > -1) {
        contactsCallback_footmarkdetail.trigger();
    } else if (href.indexOf(newfootmark) > -1) {
        contactsCallback_newfootmark.trigger();
    }
}

//日期控件初始化
function loadDatepicker(date) {
    var monthNames = ['1月', '2月', '03月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
    var calendarInline = myApp.calendar({
        input: '#new0 a.drop_picker',
        value: [new Date(date)],
        maxDate: GetDateStr(0),
        monthNames: monthNames,
        dateFormat: 'yyyy-mm-dd',
        dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
        toolbarTemplate:
        '<div class="toolbar calendar-custom-toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
        '</div>' +
        '<div class="center"></div>' +
        '<div class="right">' +
        '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
        '</div>' +
        '</div>' +
        '</div>',
        onOpen: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
            $$('.calendar-custom-toolbar .left .link').on('click', function () {
                calendarInline.prevMonth();
            });
            $$('.calendar-custom-toolbar .right .link').on('click', function () {
                calendarInline.nextMonth();
            });
        },
        onMonthYearChangeStart: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
        },
        onDayClick: function (p, dayContainer, year, month, day) {
            $$("#new0 a.drop_picker.year").html(year + "年 " + checkTime(parseInt(month) + 1) + "月 " + checkTime(day) + "日" + '<i class="iconfont icon-jiantou"></i>');
            $$("#new0 a.drop_picker.year").attr("date", year + "-" + checkTime(parseInt(month) + 1) + "-" + checkTime(day));
        }
    });
    var myDate = new Date(date);
    var nowy = myDate.getFullYear(); //当前年
    var nowm = myDate.getMonth() + 1; //当前月
    var nowd = myDate.getDate(); //当前日
    var datettml = nowy + "年 ";
    datettml += checkTime(nowm) + "月 ";
    datettml += checkTime(nowd) + "日";
    datettml += '<i class="iconfont icon-jiantou"></i>';
    $$("#new0 a.drop_picker.year").html(datettml).attr("date", nowy + "-" + checkTime(nowm) + "-" + checkTime(nowd));
}

function loadDatepicker1(date) {
    var monthNames = ['1月', '2月', '03月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
    var calendarInline = myApp.calendar({
        input: '#new1 a.drop_picker',
        value: [new Date(date)],
        maxDate: GetDateStr(0),
        monthNames: monthNames,
        dateFormat: 'yyyy-mm-dd',
        dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
        toolbarTemplate:
        '<div class="toolbar calendar-custom-toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
        '</div>' +
        '<div class="center"></div>' +
        '<div class="right">' +
        '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
        '</div>' +
        '</div>' +
        '</div>',
        onOpen: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
            $$('.calendar-custom-toolbar .left .link').on('click', function () {
                calendarInline.prevMonth();
            });
            $$('.calendar-custom-toolbar .right .link').on('click', function () {
                calendarInline.nextMonth();
            });
        },
        onMonthYearChangeStart: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
        },
        onDayClick: function (p, dayContainer, year, month, day) {
            $$("#new1 a.drop_picker.year").html(year + "年 " + checkTime(parseInt(month) + 1) + "月 " + checkTime(day) + "日" + '<i class="iconfont icon-jiantou"></i>');
            $$("#new1 a.drop_picker.year").attr("date", year + "-" + checkTime(parseInt(month) + 1) + "-" + checkTime(day));
        }
    });
    var myDate = new Date(date);
    var nowy = myDate.getFullYear(); //当前年
    var nowm = myDate.getMonth() + 1; //当前月
    var nowd = myDate.getDate(); //当前日
    var datettml = nowy + "年 ";
    datettml += checkTime(nowm) + "月 ";
    datettml += checkTime(nowd) + "日";
    datettml += '<i class="iconfont icon-jiantou"></i>';
    $$("#new1 a.drop_picker.year").html(datettml).attr("date", nowy + "-" + checkTime(nowm) + "-" + checkTime(nowd));
}

function loadDatepicker2(date) {
    var monthNames = ['1月', '2月', '03月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
    var calendarInline = myApp.calendar({
        input: '#new2 a.drop_picker',
        value: [new Date(date)],
        maxDate: GetDateStr(0),
        monthNames: monthNames,
        dateFormat: 'yyyy-mm-dd',
        dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
        toolbarTemplate:
        '<div class="toolbar calendar-custom-toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
        '</div>' +
        '<div class="center"></div>' +
        '<div class="right">' +
        '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
        '</div>' +
        '</div>' +
        '</div>',
        onOpen: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
            $$('.calendar-custom-toolbar .left .link').on('click', function () {
                calendarInline.prevMonth();
            });
            $$('.calendar-custom-toolbar .right .link').on('click', function () {
                calendarInline.nextMonth();
            });
        },
        onMonthYearChangeStart: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
        },
        onDayClick: function (p, dayContainer, year, month, day) {
            $$("#new2 a.drop_picker.year").html(year + "年 " + checkTime(parseInt(month) + 1) + "月 " + checkTime(day) + "日" + '<i class="iconfont icon-jiantou"></i>');
            $$("#new2 a.drop_picker.year").attr("date", year + "-" + checkTime(parseInt(month) + 1) + "-" + checkTime(day));
        }
    });
    var myDate = new Date(date);
    var nowy = myDate.getFullYear(); //当前年
    var nowm = myDate.getMonth() + 1; //当前月
    var nowd = myDate.getDate(); //当前日
    var datettml = nowy + "年 ";
    datettml += checkTime(nowm) + "月 ";
    datettml += checkTime(nowd) + "日";
    datettml += '<i class="iconfont icon-jiantou"></i>';
    $$("#new2 a.drop_picker.year").html(datettml).attr("date", nowy + "-" + checkTime(nowm) + "-" + checkTime(nowd));
}

function loadDatepicker3(date) {
    var monthNames = ['1月', '2月', '03月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
    var calendarInline = myApp.calendar({
        input: '#new3 a.drop_picker',
        value: [new Date(date)],
        maxDate: GetDateStr(0),
        monthNames: monthNames,
        dateFormat: 'yyyy-mm-dd',
        dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
        toolbarTemplate:
        '<div class="toolbar calendar-custom-toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
        '</div>' +
        '<div class="center"></div>' +
        '<div class="right">' +
        '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
        '</div>' +
        '</div>' +
        '</div>',
        onOpen: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
            $$('.calendar-custom-toolbar .left .link').on('click', function () {
                calendarInline.prevMonth();
            });
            $$('.calendar-custom-toolbar .right .link').on('click', function () {
                calendarInline.nextMonth();
            });
        },
        onMonthYearChangeStart: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
        },
        onDayClick: function (p, dayContainer, year, month, day) {
            $$("#new3 a.drop_picker.year").html(year + "年 " + checkTime(parseInt(month) + 1) + "月 " + checkTime(day) + "日" + '<i class="iconfont icon-jiantou"></i>');
            $$("#new3 a.drop_picker.year").attr("date", year + "-" + checkTime(parseInt(month) + 1) + "-" + checkTime(day));
        }
    });
    var myDate = new Date(date);
    var nowy = myDate.getFullYear(); //当前年
    var nowm = myDate.getMonth() + 1; //当前月
    var nowd = myDate.getDate(); //当前日
    var datettml = nowy + "年 ";
    datettml += checkTime(nowm) + "月 ";
    datettml += checkTime(nowd) + "日";
    datettml += '<i class="iconfont icon-jiantou"></i>';
    $$("#new3 a.drop_picker.year").html(datettml).attr("date", nowy + "-" + checkTime(nowm) + "-" + checkTime(nowd));
}

function loadDatepicker4(date) {
    var monthNames = ['1月', '2月', '03月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
    var calendarInline = myApp.calendar({
        input: '#new4 a.drop_picker',
        value: [new Date(date)],
        maxDate: GetDateStr(0),
        monthNames: monthNames,
        dateFormat: 'yyyy-mm-dd',
        dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
        toolbarTemplate:
        '<div class="toolbar calendar-custom-toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
        '</div>' +
        '<div class="center"></div>' +
        '<div class="right">' +
        '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
        '</div>' +
        '</div>' +
        '</div>',
        onOpen: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
            $$('.calendar-custom-toolbar .left .link').on('click', function () {
                calendarInline.prevMonth();
            });
            $$('.calendar-custom-toolbar .right .link').on('click', function () {
                calendarInline.nextMonth();
            });
        },
        onMonthYearChangeStart: function (p) {
            $$('.calendar-custom-toolbar .center').text(p.currentYear + "年" + monthNames[p.currentMonth]);
        },
        onDayClick: function (p, dayContainer, year, month, day) {
            $$("#new4 a.drop_picker.year").html(year + "年 " + checkTime(parseInt(month) + 1) + "月 " + checkTime(day) + "日" + '<i class="iconfont icon-jiantou"></i>');
            $$("#new4 a.drop_picker.year").attr("date", year + "-" + checkTime(parseInt(month) + 1) + "-" + checkTime(day));
        }
    });
    var myDate = new Date(date);
    var nowy = myDate.getFullYear(); //当前年
    var nowm = myDate.getMonth() + 1; //当前月
    var nowd = myDate.getDate(); //当前日
    var datettml = nowy + "年 ";
    datettml += checkTime(nowm) + "月 ";
    datettml += checkTime(nowd) + "日";
    datettml += '<i class="iconfont icon-jiantou"></i>';
    $$("#new4 a.drop_picker.year").html(datettml).attr("date", nowy + "-" + checkTime(nowm) + "-" + checkTime(nowd));
}
//日期选择器初始化完毕

function checkTime(k) {
    if (k.toString().length == 1) {
        k = "0" + k;
    }
    return k;
}
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期 
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1; //获取当前月份的日期 
    var d = dd.getDate();
    return y + "-" + m + "-" + d;
}
//TAB切换效果
function tab() {
    $(".find_nav_list").css("left", sessionStorage.left + "px");
    //用sessionStorage保存上次的信息
    $(".find_nav_list li").each(function () {
        if ($(this).attr("id") == sessionStorage.pagecount) {
            $(".sideline").css({ left: $(this).position().left });
            $(".sideline").css({ width: $(this).outerWidth() });
            $(this).addClass("find_nav_cur").siblings().removeClass("find_nav_cur");
            navName(sessionStorage.pagecount);
            return false;
        }
        else {
            $(".sideline").css({ left: 0 });
            $(".find_nav_list li").eq(0).addClass("find_nav_cur").siblings().removeClass("find_nav_cur");
        }
    });
    var nav_w = $(".find_nav_list li").first().width();
    $(".sideline").width(nav_w);
    $(".find_nav_list li").on('click', 'a', function () {
        var c_nav = $(this).parent().attr("id");
        nav_w = $(this).parent().width();
        $(".sideline").stop(true); //停止动画
        //移动下面的条
        $(".sideline").animate({ left: $(this).position().left }, 300);
        $(".sideline").animate({ width: nav_w });
        //更新当前元素的颜色
        if (c_nav != undefined && c_nav != null && c_nav != "") {
            $(this).parent().addClass("find_nav_cur").siblings().removeClass("find_nav_cur");
        }
        //计算导航条应该移动的距离
        var fn_w = ($(".find_nav").width() - nav_w) / 2; //导航宽度的一半
        var fnl_l;  
        var fnl_x = parseInt($(this).parent().position().left); //左边位置
        /*
        *如果在中轴线左边的，则为0
        *如果在需要移动的距离比外面容器的绝对值还大，则移动最大距离为他们的差
        *正常移动距离
        */
        if (fnl_x <= fn_w) {
            fnl_l = 0;
        } else if (fn_w - fnl_x <= flb_w - fl_w) {//溢出的宽度
            fnl_l = flb_w - fl_w;
        } else {
            fnl_l = fn_w - fnl_x;
        }
        // $(".find_nav_list").animate({
        //     "left": fnl_l
        // }, 300);
        //保存现在的距离
        sessionStorage.left = fnl_l;

        if (c_nav != undefined && c_nav != null && c_nav != "") {
            navName(c_nav);
        }
    });
    var fl_w = $(".find_nav_list").width(); //导航的总宽度
    var flb_w = $(".find_nav_left").width(); // 导航外部div的宽度
    $(".find_nav_list").on('touchstart', function (e) {
        var touch1 = e.originalEvent.targetTouches[0];
        x1 = touch1.pageX;
        y1 = touch1.pageY;
        //导航条距离左边的位置
        ty_left = parseInt($(this).css("left"));
    });
    $(".find_nav_list").on('touchmove', function (e) {
        var touch2 = e.originalEvent.targetTouches[0];
        var x2 = touch2.pageX;
        var y2 = touch2.pageY;
        //这个很重要
        if (ty_left + x2 - x1 >= 0) { //绝对移动的距离大于0
            $(this).css("left", 0);
        } else if (ty_left + x2 - x1 <= flb_w - fl_w) { //移动的距离比右侧还小
            $(this).css("left", flb_w - fl_w);
        } else {//在区间内
            $(this).css("left", ty_left + x2 - x1);
        }
        if (Math.abs(y2 - y1) > 0) {
            e.preventDefault();
        }
    });
}
function navName(c_nav) {
    switch (c_nav) {
        case "0":
            sessionStorage.pagecount = "0";
            $$('#new0').attr('style', 'display:block');
            $$('#new1').attr('style', 'display:none');
            $$('#new2').attr('style', 'display:none');
            $$('#new3').attr('style', 'display:none');
            $$('#new4').attr('style', 'display:none');
            break;
        case "1":
            sessionStorage.pagecount = "1";
            $$('#new0').attr('style', 'display:none');
            $$('#new1').attr('style', 'display:block');
            $$('#new2').attr('style', 'display:none');
            $$('#new3').attr('style', 'display:none');
            $$('#new4').attr('style', 'display:none');
            break;
        case "2":
            sessionStorage.pagecount = "2";
            $$('#new0').attr('style', 'display:none');
            $$('#new1').attr('style', 'display:none');
            $$('#new2').attr('style', 'display:block');
            $$('#new3').attr('style', 'display:none');
            $$('#new4').attr('style', 'display:none');
            break;
        case "3":
            sessionStorage.pagecount = "3";
            $$('#new0').attr('style', 'display:none');
            $$('#new1').attr('style', 'display:none');
            $$('#new2').attr('style', 'display:none');
            $$('#new3').attr('style', 'display:block');
            $$('#new4').attr('style', 'display:none');
            break;
        case "4":
            sessionStorage.pagecount = "4";
            $$('#new0').attr('style', 'display:none');
            $$('#new1').attr('style', 'display:none');
            $$('#new2').attr('style', 'display:none');
            $$('#new3').attr('style', 'display:none');
            $$('#new4').attr('style', 'display:block');
            break;
    }

}
//得到地址坐标
function getAddress() {
    var geolocation = new BMap.Geolocation();
    var pt;
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            showPosition(r)
            $$('.locate').attr('lat', r.point.lat);
            $$('.locate').attr('lng', r.point.lng);
            $$('.locate').each(function () {
                $$(this).on("click", function () {
                    mainView.router.load({ url: '../../view/footmark/locationSelect.html?lat=' + $$(this).attr("lat") + "&lng=" + $$(this).attr("lng") + "&index=" + $$(this).parent().attr("id"), reload: false });
                });
            });
        }
    });
}
//得到地址名称
function showPosition(r) {
    // ak = appkey 访问次数流量有限制
    var url = 'http://api.map.baidu.com/geocoder/v2/?ak=P6VrB5UEVvbu1wifaYtlMF2BDpgG13oX&callback=?&location=' + r.point.lat + ',' + r.point.lng + '&output=json&pois=1';
    $.getJSON(url, function (res) {
        $$('.locate').html("<span></span>" + res.result.formatted_address + "<a href='#' class='skip'></a>")
    });
}
//将地址转换为BASE64
function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, img.width, img.height);
    var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
    var dataURL = canvas.toDataURL("image/" + ext);
    return dataURL;
}
//懒加载图片
function loadImage(obj, url, callback, i) {
    var img = new Image;
    img.src = url; // "http://localhost:666/Common/website/assets/images/images-guiyang/elements/plane.jpg";
    img.crossOrigin = "*";
    // 判断图片是否在缓存中
    if (img.complete) {
        callback(img, obj, i);
        return;
    }

    // 图片加载到浏览器的缓存中回调函数
    img.onload = function () {
        callback(img, obj, i);
    }
}
//懒加载回调
function showImage(img, obj, i) {
    //obj.src = this.src;

    var base64 = img.url; //   getBase64Image(img);
    $(obj).css("background-image", "url(" + base64 + ")");
    $('#upload-container' + i).append(obj);
}

function cancelBubble(e) {
    var evt = e ? e : window.event;
    if (evt.stopPropagation) {        //W3C 
        evt.stopPropagation();
    } else {       //IE      
        evt.cancelBubble = true;
    }
}
initData();